namespace SelfManagement.Database.MySql.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class article : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ArticleCategory",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        CategoryName = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                        ListOrder = c.Int(),
                        User_Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        IsDelete = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false, precision: 0),
                        UpdatedTime = c.DateTime(nullable: false, precision: 0),
                        UpdatedBy = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                        CreatedBy = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.User_Id, cascadeDelete: true)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.Article",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        Title = c.String(nullable: false, maxLength: 200, storeType: "nvarchar"),
                        Content = c.String(unicode: false),
                        UpdateTime = c.DateTime(nullable: false, precision: 0),
                        Category_Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        ViewPermission = c.Int(nullable: false),
                        IsTop = c.Boolean(nullable: false),
                        ViewCount = c.Int(nullable: false),
                        User_Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        IsDelete = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false, precision: 0),
                        UpdatedTime = c.DateTime(nullable: false, precision: 0),
                        UpdatedBy = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                        CreatedBy = c.String(nullable: false, maxLength: 50, storeType: "nvarchar"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ArticleCategory", t => t.Category_Id, cascadeDelete: true)
                .ForeignKey("dbo.User", t => t.User_Id, cascadeDelete: true)
                .Index(t => t.Category_Id)
                .Index(t => t.User_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Article", "User_Id", "dbo.User");
            DropForeignKey("dbo.Article", "Category_Id", "dbo.ArticleCategory");
            DropForeignKey("dbo.ArticleCategory", "User_Id", "dbo.User");
            DropIndex("dbo.Article", new[] { "User_Id" });
            DropIndex("dbo.Article", new[] { "Category_Id" });
            DropIndex("dbo.ArticleCategory", new[] { "User_Id" });
            DropTable("dbo.Article");
            DropTable("dbo.ArticleCategory");
        }
    }
}
